import { Component, OnInit } from '@angular/core';
import { NzMessageService } from 'ng-zorro-antd';


declare var form: any;
declare var map: any;
@Component({
  selector: 'coordinate-local',
  templateUrl: './coordinate.component.html',
  styleUrls: ['./coordinate.component.scss']
})
export class CoordinateLocationComponent implements OnInit {

  dlx = null;
  dly = null;
  tyx = null;
  tyy = null;

  ss: any = null;
  localCount = 0;

  constructor(private msg: NzMessageService) {

  }

  ngOnInit() {
  }



  localByCoordinate(type: string) {
    if (!form.ConfigService.map) {
      this.msg.error('地图未加载完成');
      return;
    }

    let point: [number, number] = [0, 0];

    if (type === 'dl') {
      point = [this.dlx, this.dly];
      form.ConfigService.map.zoomToPoint(
        this.dlx, this.dly, 14
      );


      this.localCount++;
      if (this.ss) {
        this.ss.clear();
        // 高亮
        const ower = this;
        map.Factory.Utils('TerraformerUtils', (terraformerUtils) => {
          let geometry = terraformerUtils.WktToGeoGeometry('POINT(' + point[0] + ' ' + point[1] + ')');
          // 组装feature对象
          const feature: any = {};
          feature.properties = {};
          feature.geometry = geometry;
          feature.type = 'Feature';
          feature.properties.id = ower.localCount;
          ower.ss.highlight(feature);
        });
      } else {
        const ower = this;
        map.Factory.SimpleSearch('AttributeSearch', (attributeSearch) => {
          ower.ss = attributeSearch;
          attributeSearch.clear();
          // 高亮
          map.Factory.Utils('TerraformerUtils', (terraformerUtils) => {
            let geometry = terraformerUtils.WktToGeoGeometry('POINT(' + point[0] + ' ' + point[1] + ')');
            // 组装feature对象
            const feature: any = {};
            feature.properties = {};
            feature.geometry = geometry;
            feature.type = 'Feature';
            feature.properties.id = ower.localCount;
            attributeSearch.highlight(feature);
          });
        });
      }


    }

    if (type === 'ty') {
      const ower = this;
      this.localCount++;

      map.Factory.Utils('TransformUtils', (transformUtils) => {
        point = transformUtils.Mercator2lonLat(this.tyx, this.tyy);
        form.ConfigService.map.zoomToPoint(
          point[0], point[1], 14
        );
        if (this.ss) {
          this.ss.clear();
          // 高亮
          map.Factory.Utils('TerraformerUtils', (terraformerUtils) => {
            let geometry = terraformerUtils.WktToGeoGeometry('POINT(' + point[0] + ' ' + point[1] + ')');
            // 组装feature对象
            const feature: any = {};
            feature.properties = {};
            feature.geometry = geometry;
            feature.type = 'Feature';
            feature.properties.id = ower.localCount;
            ower.ss.highlight(feature);
          });
        } else {
          map.Factory.SimpleSearch('AttributeSearch', (attributeSearch) => {
            ower.ss = attributeSearch;
            attributeSearch.clear();
            // 高亮
            map.Factory.Utils('TerraformerUtils', (terraformerUtils) => {
              let geometry = terraformerUtils.WktToGeoGeometry('POINT(' + point[0] + ' ' + point[1] + ')');
              // 组装feature对象
              const feature: any = {};
              feature.properties = {};
              feature.geometry = geometry;
              feature.type = 'Feature';
              feature.properties.id = ower.localCount;
              attributeSearch.highlight(feature);
            });
          });
        }

      });
    }



  }


}
